package com.GainLoop.Api;

import org.json.JSONException;
import org.json.JSONObject;

import com.GainLoop.Api.Entity.EntityAbstract;

public abstract class ApiResponseAbstract<E, T extends EntityAbstract>
{

	final String CODE_KEY = "code";
	final String DATA_KEY = "data";
	
	
	protected int _retCode;
	protected E _data;
	
	private Class<T> _classT;

	
	public ApiResponseAbstract(int retCode, E data, Class<T> classT)
	{
		_retCode = retCode;
		_data = data;
		
		_classT = classT;
	}
	
	public ApiResponseAbstract(JSONObject response, Class<T> classT) throws JSONException
	{
		_classT = classT;
		
		_retCode = response.optInt("code");
		_data = _getData(response);
	}
	
	public int getReturnCode()
	{
		return _retCode;
	}
	
	public E getData()
	{
		return _data;
	}
	
	protected abstract E _getData(JSONObject response) throws JSONException;
	
	protected Class<T> getClassT()
	{
		return _classT;
	}
	
}
